package com.zzb.servlet.producttype;


import com.alibaba.fastjson.JSONObject;
import com.zzb.DTO.ResultDTO;
import com.zzb.VO.ProductTypeVO;
import com.zzb.service.ProductTypeService;
import com.zzb.service.impl.ProductTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/back/product/type/id")
public class ProductTypeFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        try {
            //得到前端数据
            String id = req.getParameter("id");
            //封装
            ProductTypeVO productTypeVO = new ProductTypeVO();
            productTypeVO.setId(Integer.valueOf(id));

            //调用逻辑层
            ProductTypeService productTypeService = new ProductTypeServiceImpl();
            //得到响应数据
            ResultDTO resultDTO = productTypeService.findById(productTypeVO);
            //将数据响应给前端
            resp.getWriter().println(JSONObject.toJSONString(resultDTO));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
